const welcomeList = [
    {
        title: '商品总数',
        count: 0,
        icon: 'fa-user',
    },
    {
        title: '用户总数',
        count: 0,
        icon: 'fa-user',
    },
];

function view() {
    $('.welcomeList').html(
        welcomeList.reduce((result, item) => {
            return (
                result +
                `
            <div class="item" style="display: flex;">
                <div class="item-data" style="display: flex; flex-direction: column;">
                    <div class="item-title">${item.title}</div>
                    <div class="item-count">${item.count}</div>
                </div>
                <div class="item-icon">
                    <i class="fa ${item.icon}"></i>
                </div>
            </div>
        `
            );
        }, '')
    );
}

window.addEventListener('load', () => {
    view();
    $.ajax({
        url: '/common/information',
        method: 'get',
        success(res) {
            welcomeList[0].count = res.goods;
            welcomeList[1].count = res.users;
            view();
        },
    });
});
